package multidraw.tools;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Icon;

import multidraw.model.DrawingCanvasModel;
import multidraw.model.commands.AddShapeCommand;
import multidraw.model.commands.DeleteObjectCommand;
import multidraw.model.commands.WrapperCommand;



public class EraserToolController extends AbstractAction {
	protected DrawingCanvasModel model;	
	
	public EraserToolController(String name, Icon icon, String tip,
			DrawingCanvasModel model) {
		super(name, icon);
		this.model = model;		
	}
	
	public void actionPerformed(ActionEvent e) {
		//if an object is selected
		//delete it.
		if (model.getSelectedObjectIndex() >= 0) {
			//model.deleteSelectedObject();
		    DeleteObjectCommand command = new DeleteObjectCommand (model.getSelectedObject().getShapeID());
		    //model.addCommand(command);
		    
			try {
				WrapperCommand wrapCmd = new WrapperCommand(command);
				model.addCommand(wrapCmd);
			} catch (Exception e1) {
				System.out.println(e1);
			}
		}
	}
}
